package com.yc.cloud.basic.rsa;

import java.security.PrivateKey;
import java.security.PublicKey;

public class RSADemo {
    public static void main(String[] args) {
        try {
            // 生成密钥对
            RSAKeyPairGenerator keyPairGenerator = new RSAKeyPairGenerator();
            PublicKey publicKey = keyPairGenerator.getPublicKey();
            PrivateKey privateKey = keyPairGenerator.getPrivateKey();

            // 原始数据
            String originalText = "Hello, world!";

            // 使用公钥加密
            String cipherText = RSAUtil.encrypt(originalText, publicKey);
            System.out.println("加密后的文本: " + cipherText);

            // 使用私钥解密
            String decryptedText = RSAUtil.decrypt(cipherText, privateKey);
            System.out.println("解密后的文本: " + decryptedText);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
